﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.Domain;
using System.Data.Entity.ModelConfiguration;

namespace MyVoteMVC.Data.Mapping
{
    public class VT_ItemsMap : EntityTypeConfiguration<VT_Items>
    {
        public VT_ItemsMap()
        {
            // Primary Key
            this.HasKey(t => t.Item_ID);

            // Properties
            this.Property(t => t.Item_ID)
                .IsRequired()
                .HasMaxLength(36);

            this.Property(t => t.Question_ID)
                .HasMaxLength(36);

            this.Property(t => t.Project_ID)
                .HasMaxLength(36);

            this.Property(t => t.Item_Title)
                .HasMaxLength(300);

            this.Property(t => t.Created_By)
                .HasMaxLength(100);

            this.Property(t => t.Created_Action)
                .HasMaxLength(200);

            this.Property(t => t.Last_Update_By)
                .HasMaxLength(100);

            this.Property(t => t.Last_Update_Action)
                .HasMaxLength(200);

            this.Ignore(t => t.Item_IfDefaultText);

            // Table & Column Mappings
            this.ToTable("VT_Items");
            this.Property(t => t.Item_ID).HasColumnName("Item_ID");
            this.Property(t => t.Question_ID).HasColumnName("Question_ID");
            this.Property(t => t.Item_No).HasColumnName("Item_No");
            this.Property(t => t.Item_Title).HasColumnName("Item_Title");
            this.Property(t => t.Item_Content).HasColumnName("Item_Content");
            this.Property(t => t.Item_IfDefault).HasColumnName("Item_IfDefault");
            this.Property(t => t.Created_By).HasColumnName("Created_By");
            this.Property(t => t.Created_Date).HasColumnName("Created_Date");
            this.Property(t => t.Created_Action).HasColumnName("Created_Action");
            this.Property(t => t.Last_Update_By).HasColumnName("Last_Update_By");
            this.Property(t => t.Last_Update_Date).HasColumnName("Last_Update_Date");
            this.Property(t => t.Last_Update_Action).HasColumnName("Last_Update_Action");
            this.Property(t => t.Online_Count).HasColumnName("Online_Count");
            this.Property(t => t.Offline_Count).HasColumnName("Offline_Count");
            this.Property(t => t.View_Count).HasColumnName("View_Count");

            // Relationships
            this.HasRequired(t => t.Question)
                .WithMany(t => t.Items)
                .HasForeignKey(d => d.Question_ID);

            this.HasOptional(t => t.Project)
                .WithMany(t => t.Items)
                .HasForeignKey(t => t.Project_ID);

            this.HasRequired(t => t.ItemImage)
            .WithRequiredPrincipal();

        }
    }

    public class VT_ItemImageMap : EntityTypeConfiguration<VT_ItemImage>
    {
        public VT_ItemImageMap()
        {

            this.HasKey(t => t.Item_ID);

            this.ToTable("VT_Items");
            this.Property(t => t.Item_Image).HasColumnName("Item_Image");

        }
    }
}
